package net.zigin.nhi.could.waste.service.impl;

import net.zigin.commons.util.ReflectUtil;
import net.zigin.commons.util.StringUtil;
import net.zigin.nhi.could.waste.aop.LoginAspect;
import net.zigin.nhi.could.waste.dao.SysUserHospitalMapper;
import net.zigin.nhi.could.waste.vo.TokenInfoBo;
import net.zigin.nhi.could.waste.dto.WarnWeightDto;
import net.zigin.nhi.could.waste.vo.WarnWeightVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.zigin.nhi.could.waste.dao.BaseMapper;
import net.zigin.nhi.could.waste.dao.WarnWeightMapper;
import net.zigin.nhi.could.waste.model.WarnWeight;
import net.zigin.nhi.could.waste.service.WarnWeightService;

import java.util.Date;
import java.util.List;

/*#################################################################*
# 说明:以下代码通过哲勤代码生成工具自动生成    
# 工具:GeneratorCode
# 作者:mgw1986                                                  
# 生成时间:2021-9-20 19:47:12                                               
##################################################################*/


/**
 *  WarnWeight服务实现类
 * @ClassName: WarnWeightServiceImpl
 * @author mgw1986
 * @date 2021-9-20 19:47:12
 * @version V1.0
 */
@Service
public class WarnWeightServiceImpl extends AbstractServiceImpl<WarnWeight, String> implements WarnWeightService{
	@Autowired
	private WarnWeightMapper warnWeightMapper;
	@Autowired
	private SysUserHospitalMapper sysUserHospitalMapper;

	@Override
	public BaseMapper<WarnWeight, String> getMapper() {
		return warnWeightMapper;
	}

	@Override
	public List<WarnWeightVo> getList() {
		TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
		String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
		return warnWeightMapper.getInfoList(hospitalBaseId);
	}

	@Override
	public String saveOrUpdate(WarnWeightDto warnWeightDto) {
		TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
		WarnWeight warnWeight = ReflectUtil.copyProperties(warnWeightDto, WarnWeight.class);
		if(StringUtil.isNullOrEmpty(warnWeightDto.getId())){
			warnWeight.setId(StringUtil.get32UUID());
			warnWeight.setCreateTime(new Date());
			warnWeight.setCreateUser(tokenInfo.getLoginName());
			warnWeight.setModifyTime(new Date());
			warnWeightMapper.insert(warnWeight);
		}else {
			warnWeight.setModifyTime(new Date());
			warnWeight.setModifyUser(tokenInfo.getLoginName());
			warnWeightMapper.updateByPrimaryKeySelective(warnWeight);
		}
		return warnWeight.getId();
	}


}